// #include"logger.hpp"
#include "server.hpp"


#define HOST "127.0.0.1" // 拒绝远程登录， 所以使用127.0.0.1进行内网登录
#define PORT 3306
#define USER "root"
#define PASS "050327Jsk"
#define DBNAME "gobang"

void mysql_test()
{
    MYSQL *mysql = mysql_util::mysql_create(HOST, USER, PASS, DBNAME, PORT);
    const char *sql = "insert stu values(null,'李四',18,40,50,70);"; // 增
    if (mysql_util::mysql_exec(mysql, sql) == false)
    {
        printf("插入失败\n");
        return;
    }
    mysql_util::mysql_destroy(mysql);
}

void json_test()
{
    // 1.将需要序列话的数据，存储到Json::Value种
    Json::Value root;
    std::string body;
    root["姓名"] = "小明";
    root["年龄"] = 18;
    root["成绩"].append(98);
    root["成绩"].append(88.5);
    root["成绩"].append(78.5);
    json_util::serialize(root, body); // 序列化
    DBG_LOG("%s", body.c_str());

    Json::Value val;                   // 记得要新建一个Json::Value对象
    json_util::unserialize(body, val); // 反序列化

    // 5.逐个访问value中的数据对象
    std::cout << "姓名：" << val["姓名"].asString() << std::endl;
    std::cout << "年龄：" << val["年龄"].asInt() << std::endl;
    int sz = val["成绩"].size();
    for (int i = 0; i < sz; i++)
    {
        std::cout << "成绩：" << val["成绩"][i].asFloat() << std::endl;
    }
}

void string_test()
{
    std::string str = ",...,,123,234,,,,,345,,,,";
    std::vector<std::string> arry;
    string_util::split(str, ",", arry);
    for (auto s : arry)
    {
        DBG_LOG("%s", s.c_str());
    }
}

void file_test()
{
    std::string str = "./logger.hpp"; // 文件路径！！！！！！！！
    std::string asc;
    file_util::read(str, asc);
    DBG_LOG("%s", asc.c_str());
}


void db_test()
{
    user_table it (HOST, USER, PASS, DBNAME); // 初始化
    Json::Value user;
    //user["username"] = "王五";
    //user["password"] = "123123";
    bool ret = it.lose(1);
    if(ret == false)
    {
        std::cout<<"查询失败"<<std::endl;
        return ;
    }
    //std::string str;
    //json_util::serialize(user,str);
    //std::cout<<str<<std::endl;
}


void online_test()
{
    online_manager on;
    wsserver_t::connection_ptr connect;
    uint64_t uid = 2;
    on.enter_room(uid,connect);
    if(on.is_in_room(uid) == false)
    {
        DBG_LOG("not in room");
    }
    else{
        DBG_LOG(" in room");
    }
    on.exit_room(uid);
    if(on.is_in_room(uid) == false)
    {
        DBG_LOG("not in room");
    }
    else{
        DBG_LOG(" in room");
    }
}

void room_test()
{
    online_manager on;
    user_table it (HOST, USER, PASS, DBNAME); // 初始化
    room_manager rm(&it,&on);
    auto ptr = rm.create_room(10,20);
    room r(10,&it,&on);//三个参数------uint64_t _id, user_table *_user_tb, online_manager *_online_user
    matcher m(&rm,&it,&on);
}

void server_test()
{
    gobang_server _server(HOST, USER, PASS, DBNAME,PORT);
    _server.start(8081);
}

int main() 
{
    server_test();
    return 0;
}